package com.chexiehui.jc.utils;

import android.annotation.SuppressLint;
import android.os.CountDownTimer;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.chexiehui.jc.R;

public class CodeCountDownTimer extends CountDownTimer {
    private TextView mTextView;

    public CodeCountDownTimer(TextView textView, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.mTextView = textView;
    }

    @SuppressLint("DefaultLocale")
    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setEnabled(false);//重新获得点击
        mTextView.setText(String.format("%d秒后重新获取", (int)millisUntilFinished / 1000));
        mTextView.setTextColor(ContextCompat.getColor(mTextView.getContext(), R.color.app_color));
    }

    @Override
    public void onFinish() {
        mTextView.setText("重新获取");
        mTextView.setEnabled(true);//重新获得点击
        mTextView.setTextColor(ContextCompat.getColor(mTextView.getContext(), R.color.c_666666));
    }

    public void release(){
        cancel();
        mTextView = null;
    }
}
